package com.example.demo.controller;


import com.example.demo.entity.Charges;
import com.example.demo.pojo.PlannerResult;
import com.example.demo.repository.ChargesRepository;
import com.example.demo.vo.ChargesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/charges")
public class ChargesController {

    @Autowired
    ChargesRepository chargesRepository;
/*
@PostMapping("/findall")
    public List<Charges> findAll()
    {
        return chargesRepository.findAll();
    }

    @GetMapping("/findchargesbyid/{id}")
    public Charges findChargesById(@PathVariable("id") Integer id)
    {
        return chargesRepository.findById(id).get();
    }
    @PutMapping("/update")
    public String update(@RequestBody Charges charges){
        Charges result =chargesRepository.save(charges);
        if(result !=null)
        {
            return "success";
        }
        else {
            return "error";
        }
    }
    @DeleteMapping("/deletebyid/{id}")
    public  void deleteByid(@PathVariable("id")  Integer id){
        chargesRepository.deleteById(id);

    }
 */


    @PostMapping("/save")
    public PlannerResult<String> createcharges(@RequestBody ChargesVo chargesVo)
    {
        Charges charges=new Charges();
        charges.setActivity_id(chargesVo.getActivity_id());
        charges.setBooking_fee(chargesVo.getBooking_fee());
        charges.setActual_fee(charges.getActual_fee());
        Charges result=chargesRepository.save(charges);
        if(result.getId() !=null)
        {
            return PlannerResult.success("success");
        }
        else {
            return PlannerResult.error("error");
        }
    }





}
